package com.bwie.controller;

import com.bwie.pojo.User;
import com.bwie.service.UserService;
import com.bwie.utils.R;
import com.bwie.vo.LoginForm;
import com.bwie.vo.PageInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * description:
 *
 * @Author chentong
 * @Create 2025/4/23 8:16
 * @Version 1.0
 */
@RestController
@RequestMapping("/user/user")
@Api(tags = "用户管理")
public class UserController {

    @Autowired
    UserService userService;


    /**
     * 用户分页列表查询
     * @param pageInfoVo
     * @return
     */
    @ApiOperation(value = "用户分页列表查询")
    @PostMapping("/getUserList")
    public R getUserList(@RequestBody PageInfoVo pageInfoVo){
        return userService.getUserList(pageInfoVo);
    }

    /**
     * 管理员登录
     * @param loginForm
     * @return
     */
    @ApiOperation(value = "管理员登录")
    @PostMapping("/adminLogin")
    public R adminLogin(@RequestBody LoginForm loginForm){
        return userService.adminLogin(loginForm);
    }

    /**
     * 用户注册
     * @param user
     * @return
     */
    @ApiOperation(value = "用户注册")
    @PostMapping("/userReg")
    public R userReg(@RequestBody @Validated User user){
        return userService.userReg(user);
    }

    /**
     * 用户审核
     * @param user
     * @return
     */
    @ApiOperation(value = "用户审核")
    @PostMapping("/checkUser")
    public R checkUser(@RequestBody User user){
        return userService.checkUser(user);
    }

    /**
     * 我的信息(用户详情)
     * @return
     */
    @ApiOperation(value = "我的信息")
    @PostMapping("/getMyInfo")
    public R getMyInfo(){
        return userService.getMyInfo();
    }

    /**
     * 修改用户信息
     * @param user
     * @return
     */
    @ApiOperation(value = "修改用户信息")
    @PostMapping("/updateUser")
    public R updateUser(@RequestBody  User user){
        return userService.updateUser(user);
    }


    /**
     * 图片上传
     * @param file
     * @return
     */
    @ApiOperation(value = "图片上传")
    @PostMapping("/uploadFile")
    public R uploadFile(@RequestPart("file") MultipartFile file){
        return userService.uploadFile(file);
    }

    /**
     * 单个删除用户
     * @param id
     * @return
     */
    @ApiOperation(value = "单个删除用户")
    @PostMapping("/deleteUserById/{id}")
    public R deleteUserById(@PathVariable(name = "id")Integer id){
        return userService.deleteUserById(id);
    }

    /**
     * 获取当前角色列表
     * @return
     */
    @ApiOperation(value = "获取当前用户角色")
    @PostMapping("/getUserRoleList")
    public R getUserRoleList(){
        return userService.getUserRoleList();
    }

    /**
     * 获取当前用户菜单树
     * @return
     */
    @ApiOperation(value = "获取当前用户菜单树")
    @PostMapping("/getUserMenuTree")
    public R getUserMenuTree(){
        return userService.getUserMenuTree();
    }
}
